package com.ruoyi.web.controller.cs;

import com.ruoyi.common.annotation.CheckSwitch;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.cs.domain.TFringeBenefits;
import com.ruoyi.cs.domain.vo.TFringeBenefitsDailyVo;
import com.ruoyi.cs.domain.vo.TFringeBenefitsVo;
import com.ruoyi.cs.service.ITFringeBenefitsService;
import com.ruoyi.cs.service.ITUserService;
import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * 福利日常活动Controller
 *
 * @author ruoyi
 * @date
 */
@Api(tags = {"福利日常活动"})
@RestController
@RequestMapping("/cs/benefits")
public class TFringeBenefitsController extends BasicsController {
    private static final Logger log = LoggerFactory.getLogger(TFringeBenefitsController.class);
    @Autowired
    private ITFringeBenefitsService itFringeBenefitsService;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private ITUserService tUserService;

    /**
     * 领取记录列表
     *
     * @param tFringeBenefits
     * @return
     */
    @PreAuthorize("@ss.hasPermi('cs:benefits:list')")
    @ApiOperation("每日福利后台领取记录列表")
    @RequestMapping(name = "每日福利后台领取记录列表", value = "list", method = RequestMethod.POST)
    public ResponsePageInfo<TFringeBenefits> listBack(@RequestBody TFringeBenefits tFringeBenefits) {
        startPage(tFringeBenefits.getPageNum(), tFringeBenefits.getPageSize());
        List<TFringeBenefits> tFringeBenefitsList = itFringeBenefitsService.selectTFringeBenefitsList(tFringeBenefits);
        return toResponsePageInfo(tFringeBenefitsList);
    }
    /*-----------------------------------------------------------前台接口-----------------------------------------------------------------------*/

    @ApiOperation("每日福利")
    @RequestMapping(name = "每日福利", value = "dailyActivities", method = RequestMethod.GET)
    public Response<TFringeBenefitsVo> dailyActivities() {
        String userId = tokenService.getLoginUserId();
        TFringeBenefitsVo tFringeBenefitsVo = itFringeBenefitsService.compensateInfo(userId);
        return Response.success(tFringeBenefitsVo);
    }

    @CheckSwitch
    @ApiOperation("每日福利领取")
    @RequestMapping(name = "每日福利领取", value = "immediatelyReceive", method = RequestMethod.GET)
    @Log(title = "每日福利领取", businessType = BusinessType.OTHER)
    public Response<TFringeBenefitsDailyVo> immediatelyReceive(@RequestParam(value = "dateCode",required = true,defaultValue = "1") Integer dateCode) {
        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
        if (loginUser.getUser() == null) {
            return Response.fail("请先登录！");
        }
        return Response.fail("系统升级中，请耐心等待！");
//        SysUser sysUser = loginUser.getUser();
//        String userId = sysUser.getLoginUserId();
//        return itFringeBenefitsService.immediatelyReceive(userId,dateCode);
    }

    @ApiOperation("每日福利领取记录")
    @RequestMapping(name = "每日福利领取记录", value = "receivingRecords", method = RequestMethod.GET)
    public Response<List<TFringeBenefits>> receivingRecords() {
        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
        if (loginUser.getUser() == null) {
            return Response.fail("请先登录！");
        }
        SysUser sysUser = loginUser.getUser();
        String userId = sysUser.getLoginUserId();
        List<TFringeBenefits> tFringeBenefits = itFringeBenefitsService.receivingRecords(userId);
        return Response.success(tFringeBenefits);
    }
}
